<?php

namespace app\api\controller;

use app\admin\model\Form1;
use app\admin\model\Form2;
use app\admin\model\Form3;
use app\admin\model\Form7;
use app\admin\model\Form8;
use app\api\logic\FormLogic;
use app\BaseController;
use think\Exception;
use think\facade\Cache;

class Index extends BaseController
{
    //默认输出
    public function index()
    {
        return result(1,'疫情防控系统API');
    }

    //返沙人员信息填报
    public function form1()
    {
        $post = $this->request->post();
        $rule = [
            'name|姓名'                          =>  'require|chs',
            'sex|性别'                           =>  'require',
            'id_card|身份证号'                   =>  'require|idCard',
            'arrival_time|到沙时间'              =>  'require|date',
            'check_time|最近一次核酸检测时间'     =>  'require|date',
            'check_result|核酸检测结果'          =>  'require',
            'domicile|户籍所在地'                =>  'require',
            'departure|出发地'                   =>  'require',
            'community|居住地所属社区'           =>  'require',
            'mobile|手机号'                      =>  'require|mobile',
            'image1|健康码'                      =>  'require',
            'image2|行程码'                      =>  'require',
            'code|短信验证码'                    =>  'require',
        ];
        $this->api_validate($post, $rule);

        $result = FormLogic::createForm1($post);
        if ($result !== true) {
            return result(0, self::getError());
        }
        return result(1,'提交成功');
    }

    //疫苗接种人员信息填报
    public function form2()
    {
        $post = $this->request->post();
        $rule = [
            'name|姓名'                          =>  'require|chs',
            'id_card|身份证号'                   =>  'require|idCard',
            'living|居住地址'                    =>  'require',
            'community|居住地所属社区'           =>  'require',
            'vaccination_time|接种时间'          =>  'require|date',
            'dosage|接种剂次'                    =>  'require|in:1,2,3',
            'mobile|手机号码'                    =>  'require|mobile',
            'code|短信验证码'                    =>  'require',
        ];
        $this->api_validate($post, $rule);

        $result = FormLogic::createForm2($post);
        if ($result !== true) {
            return result(0, self::getError());
        }
        return result(1,'提交成功');
    }

    //购药人员自主填报
    public function form3()
    {
        $post = $this->request->post();
        $rule = [
            'drug_name|药品名称'                 =>  'require',
            'name|姓名'                          =>  'require|chs',
            'sex|性别'                           =>  'require',
            'id_card|身份证号'                   =>  'require|idCard',
            'town|居住地所属乡镇'                =>  'require',
            'community|居住地所属社区'           =>  'require',
            'living|居住地址'                    =>  'require',
            'buy_time|购药时间'                  =>  'require|date',
            'is_fever|是否有退烧功能'            =>  'require',
            'pharmacy|购药药店'                  =>  'require',
//            'temperature|体温'                   =>  'require',
            'mobile|手机号码'                    =>  'require|mobile',
            'code|短信验证码'                    =>  'require',
        ];
        $this->api_validate($post, $rule);

        $result = FormLogic::createForm3($post);
        if ($result !== true) {
            return result(0, self::getError());
        }
        return result(1,'提交成功');
    }

    //体温上报
    public function form7()
    {
        $post = $this->request->post();
        $rule = [
            'name|姓名'                          =>  'require|chs',
            'id_card|身份证号'                   =>  'require|idCard',
            'temperature|今日体温'               =>  'require|float',
            'mobile|手机号码'                    =>  'require|mobile',
            'code|短信验证码'                    =>  'require',
        ];
        $this->api_validate($post, $rule);

        $result = FormLogic::createForm7($post);
        if ($result !== true) {
            return result(0, self::getError());
        }
        return result(1,'提交成功');
    }

    //疫苗异常反应上报，每日可多次提交
    public function form8()
    {
        $post = $this->request->post();
        $rule = [
            'name|姓名'                          =>  'require|chs',
            'id_card|身份证号'                   =>  'require|idCard',
            'aberrant_result|疫苗是否有异常反应' =>  'require',
            'mobile|手机号码'                    =>  'require|mobile',
            'code|短信验证码'                    =>  'require',
        ];
        $this->api_validate($post, $rule);

        $result = FormLogic::createForm8($post);
        if ($result !== true) {
            return result(0, self::getError());
        }
        return result(1,'提交成功');
    }
}